package com.shawn.spring.boot.redis.converter;

import java.nio.charset.StandardCharsets;
import org.joda.money.CurrencyUnit;
import org.joda.money.Money;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.convert.ReadingConverter;

/**
 * @author shawn
 * @since 2020/9/4
 */
@ReadingConverter
public class BytesToMoneyConverter implements Converter<byte[], Money> {
  @Override
  public Money convert(byte[] source) {
    String value = new String(source, StandardCharsets.UTF_8);
    return Money.ofMinor(CurrencyUnit.of("CNY"), Long.parseLong(value));
  }
}
